
<!DOCTYPE html>
<html lang="zh-CN">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
        <meta name="description" content="">
        <meta name="author" content="">

        <title>{$sysPageTitle}</title>

        <link href="__PUBLIC__/images/favicon.ico" rel="shortcut icon" />

        <!-- Bootstrap core CSS -->
        <link rel="stylesheet" href="__PUBLIC__/css/bootstrap.min.css" />
        <link rel="stylesheet" href="__PUBLIC__/css/bootstrap-theme.min.css" />
        <link rel="stylesheet" href="__PUBLIC__/css/dashboard.css" />
        <link rel="stylesheet" href="__PUBLIC__/css/icheck/all.css" />
        <link rel="stylesheet" href="__PUBLIC__/css/select2/select2.css" />
        <link rel="stylesheet" href="__PUBLIC__/css/select2/select2-bootstrap.min.css" />
        <style>
            .nav-tabs>li.active>a, .nav-tabs>li.active>a:focus, .nav-tabs>li.active>a:hover {
                color:#fff;
                background-color: #337ab7;
            }
        </style>
    </head>

    <body>

    <include file="Common/topNav" />

    <div class="container-fluid">
        <div class="row">
            <include file="Common/leftMenu" />
            <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
                <div class="cont-title clearfix" style="margin-bottom:20px;">
                    <div class="title">预约分配列表</div>
                    <div class="btn-group">
                        <button type="button" id="addOrder" class="btn">设置预约</button>
                    </div>
                </div>
                <div class="pull-right" style="margin-left: 20px;">
                    <button type="button" id="curWeek" class="btn btn-primary">本周</button>
                    <button type="button" id="prevWeek" class="btn btn-warning">上一周</button>
                    <button type="button" id="nextWeek" class="btn btn-info">下一周</button>
                </div>
                <div class="pull-right" id="week-list">

                </div>
                <div class="clearfix"></div>
                <div class="table-responsive">
                    <table class="table table-bordered table-striped table-hover" id="tableData">
                        <thead>
                            <tr>
                                <th style="width: 150px;"></th>
                                <foreach name="orgList" item="org">
                                    <th>{$org.name}</th>
                                </foreach>
                            </tr>
                        </thead>
                        <tbody id="data_list">

                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
    <div id="img-loading"><img src="__PUBLIC__/images/loading.gif" style="width: 25px;" /></div>
    <include file="Common/modalHtmls" />
    <script type="text/javascript" src="__PUBLIC__/js/jquery.min.js"></script>
    <script type="text/javascript" src="__PUBLIC__/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="__PUBLIC__/js/icheck.min.js"></script>
    <script type="text/javascript" src="__PUBLIC__/js/common.js"></script>
    <script type="text/javascript" src="__PUBLIC__/js/select2/select2.js"></script>
    <script type="text/javascript">
        var curDayWeek = "{$curDayWeek}".replace(/-/g, "");
        $(function(){
            getWeekList(0);
            $("#curWeek").bind("click",function () {
                getWeekList(0);
            });
            $("#prevWeek").bind("click",function () {
                getWeekList(1);
            });
            $("#nextWeek").bind("click",function () {
                getWeekList(2);
            });
            $("#addOrder").click(function () {
                common.loading('正在加载...');
                common.getHtml("{:U('Admin/Appointment/add')}", {}, function (html) {
                    common.closeLoading();
                    $("#commonModal").html(html).modal({show: true, backdrop: 'static', keyboard: false});
                });
            });
            edit();
            delApp();
        });
        
        function reloadData(day) {
            $("#defaultDate").val(day);
            var loading = '<tr><td colspan="30">'+$("#img-loading").html()+'</td></tr>';
            $("#data_list").html(loading);
            getUserList();
        }

        function getWeekList(type) {
            disableWeekBtn();
            var data = {
                type: type
            };
            if($("#curDate").length){
                data.curTime = $("#curDate").val();
            }
            $("#week-list").html($("#img-loading").html());
            var loading = '<tr><td colspan="30">'+$("#img-loading").html()+'</td></tr>';
            $("#data_list").html(loading);
            $.ajax({
                url: "{:U('Admin/Appointment/getWeekList')}",
                type: "post",
                dataType: "html",
                data: data,
                success: function (data) {
                    $("#week-list").html(data);
                    enableWeekBtn();
                    getUserList();
                }
            });
        }

        function getUserList() {
            var data = {};
            if($("#defaultDate").length){
                data.curTime = $("#defaultDate").val();
            }
            $.ajax({
                url: "{:U('Admin/Appointment/getUserList')}",
                type: "post",
                dataType: "html",
                data: data,
                success: function (data) {
                    $("#data_list").html(data);
                }
            });
        }
        
        function edit() {
            $("#data_list").on('click','small',function(){
                var colDate = $("#defaultDate").val().replace(/-/g, "");
                if (colDate >= curDayWeek ) {
                    common.loading('正在加载...');
                    var id = $(this).attr("thisId");
                    common.getHtml("{:U('Admin/Appointment/add')}"+"?id="+id, {}, function (html) {
                        common.closeLoading();
                        $("#commonModal").html(html).modal({show: true, backdrop: 'static', keyboard: false});
                    });
                } else {
                    common.alert("提示","您不能修改历史预约！");
                }
            });
        }

        function delApp() {
            $("#data_list").on('click','span',function(){
                var colDate = $("#defaultDate").val().replace(/-/g, "");
                if (colDate >= curDayWeek ) {
                    var $_this = $(this);
                    var id = $_this.attr("thisId");
                    var time = $_this.attr("time");
                    common.confirm("提示","确认删除该服务人员吗？",function(){
                        $.ajax({
                            url: "{:U('Admin/Appointment/delApp')}",
                            type: "post",
                            dataType: "json",
                            data: {id:id,time:time},
                            success: function (data) {
                                if (data.status) {
                                    $_this.parent("button").remove();
                                }
                                common.alert("提示",data.msg);
                            }
                        });
                    });
                } else {
                    common.alert("提示","您不能删除历史预约！");
                }
            });
        }
        
        function enableWeekBtn() {
            $("#curWeek,#prevWeek,#nextWeek").removeClass("disabled");
            $("#curWeek,#prevWeek,#nextWeek").removeAttr("disabled");
        }
        
        function disableWeekBtn() {
            $("#curWeek,#prevWeek,#nextWeek").addClass("disabled");
            $("#curWeek,#prevWeek,#nextWeek").attr("disabled","true");
        }
    </script>
</body>
</html>
